package com.lzwork.gpt.utility.job;

import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import com.lzwork.utility.data.wrapper.DataWrapperHolder;
import com.lzwork.utility.data.wrapper.IntWrapper;
import com.lzwork.utility.data.wrapper.StringWrapper;
import com.lzwork.utility.logger.LOGGER;
import com.lzwork.utility.officeparser.ExcelSaver;

/**
 * @author LiZheng
 * @date 2024年3月13日 15:32:44
 */

public abstract class FileParseJob extends ExcelSaver
{
	public static abstract class JobSetting extends DataWrapperHolder
	{
		public final static String KEY_URL = "url";
		public final static String KEY_LOG = "logAt";
		public final static String KEY_SAVE = "saveAt";

		protected StringWrapper url = new StringWrapper(KEY_URL, null);
		protected IntWrapper logAt = new IntWrapper(KEY_LOG, 100);
		protected IntWrapper saveAt = new IntWrapper(KEY_SAVE, 0);

		public abstract String defInput();

		public abstract String defOutput();

		public int logAt()
		{
			return logAt.value();
		}

		public int saveAt()
		{
			return saveAt.value();
		}

		public String url()
		{
			return url.value();
		}
	}

	public FileParseJob(JobSetting setting)
	{
		jobSetting = createSetting();
		jobSetting.copyContents(setting);
		afterConstruct();
	}

	public FileParseJob(Map<?, ?> paramData)
	{
		jobSetting = createSetting();
		jobSetting.setMapContents(paramData);
		afterConstruct();
	}

	protected void afterConstruct()
	{
	}

	protected abstract JobSetting createSetting();

	protected JobSetting jobSetting;

	protected List<String> logs = new ArrayList<>();

	protected void log(String txt)
	{
		log(LOGGER.APP, txt);
	}

	protected void log(String type, String txt)
	{
		logs.add(LOGGER.log(type, txt));
	}

	public JobSetting getSetting()
	{
		if (jobSetting == null)
			jobSetting = createSetting();

		return jobSetting;
	}

	public abstract JSONObject doParse(File input, File output, File legacy);
}
